﻿using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ScienceAIApp.Helpers;
internal class ImageHelper
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="p"></param>
    /// <param name="size0">画布尺寸 1024 * 1024</param>
    /// <param name="size1">图像尺寸 一般小于 1024 * 1024</param>
    /// <returns></returns>
    public static double[] ConvertPoint2d(Point2d p, Size size0, Size size1)
    {
        var factor1 = (double)size1.Width / (double)size1.Height;

        // 宽度大的情况, 以宽度为准
        if (factor1 >= 1)
        {
            var factor = (double)size1.Width / (double)size0.Width;
            var x = p.X * factor;
            var diffY = (size0.Height - size1.Height / factor) / 2.0;
            var y = (p.Y - diffY) * factor;
            return new double[]{x,y};
        }

        // 以高度为准
        else
        {
            var factor = (double)size1.Height / (double)size0.Height;
            var y = p.Y * factor;
            var diffX = (size0.Width - size1.Width / factor) / 2.0;
            var x = (p.X - diffX) * factor;
            return new double[] { x, y };
        }

    }
}
